<?php

namespace app\rental\controller;

use app\rental\model\RentalReserveModel;
use cmf\controller\AdminBaseController;
use think\Db;

/**
 * Class dminTagController 豪车预约管理控制器
 * @package app\rental\controller
 */
class AdminReserveController extends AdminBaseController
{
    /**
     * 豪车预约管理
     * @adminMenu(
     *     'name'   => '豪车预约管理',
     *     'parent' => 'rental/AdminIndex/default',
     *     'display'=> true,
     *     'hasView'=> true,
     *     'order'  => 0,
     *     'icon'   => '',
     *     'remark' => '豪车预约管理',
     *     'param'  => ''
     * )
     */
    public function index()
    {
        $rentalReserveModel = new RentalReserveModel();
        $reserves           = $rentalReserveModel->paginate();
        $this->assign("arrStatus", $rentalReserveModel::$STATUS);
        $this->assign("reserves", $reserves);
        $this->assign('page', $reserves->render());
        return $this->fetch();
    }

    /**
     * 更新豪车预约管理状态
     * @adminMenu(
     *     'name'   => '更新标签状态',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> false,
     *     'order'  => 0,
     *     'icon'   => '',
     *     'remark' => '更新标签状态',
     *     'param'  => ''
     * )
     */
    public function upStatus()
    {
        $intId     = $this->request->param("id");
        $intStatus = $this->request->param("status");
        $intStatus = $intStatus ? 1 : 0;
        if (empty($intId)) {
            $this->error(lang("NO_ID"));
        }

        $rentalReserveModel = new RentalReserveModel();
        $rentalReserveModel->isUpdate(true)->save(["status" => $intStatus], ["id" => $intId]);

        $this->success(lang("SAVE_SUCCESS"),url('AdminReserve/index'));

    }

    /**
     * 删除豪车预约管理
     * @adminMenu(
     *     'name'   => '删除豪车预约管理',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> false,
     *     'order'  => 0,
     *     'icon'   => '',
     *     'remark' => '删除豪车预约管理',
     *     'param'  => ''
     * )
     */
    public function delete()
    {
        $intId = $this->request->param("id", 0, 'intval');

        if (empty($intId)) {
            $this->error(lang("NO_ID"));
        }
        $rentalReserveModel = new RentalReserveModel();

        $rentalReserveModel->where(['id' => $intId])->delete();

        $this->success(lang("DELETE_SUCCESS"));
    }
}
